class Solution:
    def add(self, a: int, b: int) -> int:
        a1, b1 = list(map(int, bin(a & 0xffffffff)[2:])), list(map(int, bin(b & 0xffffffff)[2:]))
        a1, b1 = [0]*(32-len(a1))+a1, [0]*(32-len(b1))+b1
        res = [0]*32
        c = 0

        def add(x, y, c):
            return x^y^c, x|y if c else x&y

        def origin(l):
            if l[0] == 1:
                z = len(l)-1
                for i in range(len(l)-1,-1,-1):
                    if l[i] == 1:
                        z = i
                        break
                for i in range(z):
                    l[i] = 1 if l[i] == 0 else 0
            return l


        for i in range(31,-1,-1):
            res[i], c = add(a1[i], b1[i], c)
        
        sign = res[0]
        res = origin(res)

        return int(('-' if sign == 1 else '') + '0b'+''.join(map(str,res)), base=2) 

if __name__ == '__main__':
    s = Solution()
    print(s.add(123,-13))
    